package cn.tedu.egmvc2.controller;

import cn.tedu.egmvc2.mapper.EmpMapper;
import cn.tedu.egmvc2.pojo.dto.InsertEmpDtTO;
import cn.tedu.egmvc2.pojo.entity.Emp;
import cn.tedu.egmvc2.pojo.vo.EmpVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/emp/")
public class EmpController {
    @Autowired
    private EmpMapper empMapper;

    @RequestMapping("insert")
    public String insert(InsertEmpDtTO insertEmpDtTO) {
        Emp emp = new Emp();
        BeanUtils.copyProperties(insertEmpDtTO,emp);
        empMapper.insert(emp);
        return "添加成功";
    }

    @RequestMapping("select")
    public List<EmpVO> select() {
        System.out.println(empMapper.selectAllEmp());
        return empMapper.selectAllEmp();
    }

    @RequestMapping("update")
    public String update(Emp emp){
        empMapper.updateEmp(emp);
        return "修改成功";
    }

    @RequestMapping("delete")
    public String delete(int id){
        empMapper.deleteEmp(id);
        return "删除成功";
    }

}
